import sys
import subprocess
import time
import runNQueens
from statlib import stats

def run_process(command, out):
   c_command = command + " > " + out
   p = subprocess.Popen(c_command, shell=True, stdout=subprocess.PIPE)   
   p.wait()	

if __name__ == "__main__":

   opts = sys.argv[1:]
   operators_variation = opts[0]
   command = "python  experimentNQueens.py"	

   max_generation = "5000"
   mutation = "0.08"
   xover_probability = "0.1"
   tryouts = "100"
   pops = {4:50, 8:50, 10:50, 12:50, 16:50, 32:50, 128:50, 256:50, 512:50}

   for numero_rainhas in [128, 256, 512]:
      population = str(pops[numero_rainhas])
      args =  str(numero_rainhas) + " mut " + max_generation + " " + mutation + " " + xover_probability + " " + tryouts + " " + population + " " + operators_variation
      file_name = str(numero_rainhas) + "_mut_" + max_generation + "_" + mutation + "_" + xover_probability + "_" + tryouts + "_" + population + "_" + operators_variation
      print "Mutation exp", args
      complete_command = command + " " + args		
      run_process(complete_command, file_name+".txt")


   #for numero_rainhas in [4, 8, 10, 12, 16]:
      #population = str(pops[numero_rainhas])
      #args = str(numero_rainhas) + " xover " + max_generation + " " + mutation + " " + xover_probability + " " + tryouts + " " + population + " " + operators_variation
      #file_name = str(numero_rainhas) + "_xover_" + max_generation + "_" + mutation + "_" + xover_probability + "_" + tryouts + "_" + population + "_" + operators_variation
      #print "XOver exp", args
      #complete_command = command + " " + args		
      #run_process(complete_command, file_name+".txt")